package netty.tcp.websocket;

import io.netty.channel.Channel;
import netty.tcp.tasker.TaskerMessageSender;

public class Session {

    private final int userId;

    private final String channelId;

    private final Channel channel;

    private final TaskerMessageSender taskerMessageSender;

    private final int delay = Integer.parseInt(System.getProperty("lingerTime", "500"));

    public Session(int userId, Channel channel) {
        this.userId = userId;
        this.channelId = channel.id().asLongText();
        this.channel = channel;

        taskerMessageSender = new TaskerMessageSender(this);
    }

    public int getUserId() {
        return userId;
    }

    public String getChannelId() {
        return channelId;
    }

    public Channel getChannel() {
        return channel;
    }

    public int getDelay() {
        return delay;
    }

    public void send(MessageContainer messageContainer) {
        channel.writeAndFlush(messageContainer);

//        taskerMessageSender.trigger();
    }

    public void flush() {
        channel.flush();
    }
}
